const Router = require("koa-router")
const Server = require('./server')
const Check = require('./check')
const { koaBody } = require('@config')
const { auth } = require('@/lib/auth')

/**
 * 路由对象
 * @type {Router}
 */
const router = new Router({
  prefix: '/logs'
})

/**
 * 添加前端流程日志
 */
router.post("/add-web-process", koaBody(), async (ctx) => {
  Check.addWebProcess(ctx)
  const data = await Server.addWebProcess(ctx)
  ctx.sendSuccess(data)
})

/**
 * 获取前端流程日志
 */
router.get("/web-process-list", auth, koaBody(), async (ctx) => {
  Check.webCheckList(ctx)
  const data = await Server.webProcessList(ctx)
  ctx.sendSuccess(data)
})

/**
 * 删除单个前端流程日志
 */
router.delete("/web-process-remove-one", auth, koaBody(), async (ctx) => {
  Check.removeOne(ctx)
  const data = await Server.webProcessRemoveOne(ctx)
  ctx.sendSuccess(data)
})

/**
 * 删除所有前端流程日志
 */
router.delete("/web-process-remove-all", auth, koaBody(), async (ctx) => {
  const data = await Server.webProcessRemoveAll()
  ctx.sendSuccess(data)
})

/**
 * 添加前端流程日志
 */
router.post("/add-web-ajax", koaBody(), async (ctx) => {
  Check.addWebAjax(ctx)
  const data = await Server.addWebAjax(ctx)
  ctx.sendSuccess(data)
})

/**
 * 获取前端流程日志
 */
router.get("/web-ajax-list", auth, koaBody(), async (ctx) => {
  Check.webCheckList(ctx)
  const data = await Server.webAjaxList(ctx)
  ctx.sendSuccess(data)
})

/**
 * 删除单个前端流程日志
 */
router.delete("/web-ajax-remove-one", auth, koaBody(), async (ctx) => {
  Check.removeOne(ctx)
  const data = await Server.webAjaxRemoveOne(ctx)
  ctx.sendSuccess(data)
})

/**
 * 删除所有前端流程日志
 */
router.delete("/web-ajax-remove-all", auth, koaBody(), async (ctx) => {
  const data = await Server.webAjaxRemoveAll()
  ctx.sendSuccess(data)
})

/**
 * 添加前端Error日志
 */
router.post("/add-web-error", koaBody(), async (ctx) => {
  Check.addWebError(ctx)
  const data = await Server.addWebError(ctx)
  ctx.sendSuccess(data)
})

/**
 * 获取前端Error日志
 */
router.get("/web-error-list", auth, koaBody(), async (ctx) => {
  Check.webCheckList(ctx)
  const data = await Server.webErrorList(ctx)
  ctx.sendSuccess(data)
})

/**
 * 删除单个前端Error日志
 */
router.delete("/web-error-remove-one", auth, koaBody(), async (ctx) => {
  Check.removeOne(ctx)
  const data = await Server.webErrorRemoveOne(ctx)
  ctx.sendSuccess(data)
})

/**
 * 删除所有前端Error日志
 */
router.delete("/web-error-remove-all", auth, koaBody(), async (ctx) => {
  const data = await Server.webErrorRemoveAll()
  ctx.sendSuccess(data)
})

/**
 * 获取服务器流程日志
 */
router.get("/server-process-list", auth, koaBody(), async (ctx) => {
  Check.webCheckList(ctx)
  const data = await Server.serverProcessList(ctx)
  ctx.sendSuccess(data)
})

/**
 * 删除单个服务器流程日志
 */
router.delete("/server-process-remove-one", auth, koaBody(), async (ctx) => {
  Check.removeOne(ctx)
  const data = await Server.serverProcessRemoveOne(ctx)
  ctx.sendSuccess(data)
})

/**
 * 删除所有服务器流程日志
 */
router.delete("/server-process-remove-all", auth, koaBody(), async (ctx) => {
  const data = await Server.serverProcessRemoveAll()
  ctx.sendSuccess(data)
})

/**
 * 获取服务器Error日志
 */
router.get("/server-error-list", auth, koaBody(), async (ctx) => {
  Check.webCheckList(ctx)
  const data = await Server.serverErrorList(ctx)
  ctx.sendSuccess(data)
})

/**
 * 删除单个服务器Error日志
 */
router.delete("/server-error-remove-one", auth, koaBody(), async (ctx) => {
  Check.removeOne(ctx)
  const data = await Server.serverErrorRemoveOne(ctx)
  ctx.sendSuccess(data)
})

/**
 * 删除所有服务器Error日志
 */
router.delete("/server-error-remove-all", auth, koaBody(), async (ctx) => {
  const data = await Server.serverErrorRemoveAll()
  ctx.sendSuccess(data)
})

module.exports = router




